﻿//namespace Neovolve.Toolkit.Workflow.UnitTests
//{
//    using System;
//    using Microsoft.Practices.Unity;
//    using Microsoft.VisualStudio.TestTools.UnitTesting;
//    using Neovolve.Toolkit.Workflow.Extensions;
//    using Rhino.Mocks;

//    /// <summary>
//    /// The <see cref="InstanceHandlerTests"/>
//    ///   class is used to test the <see cref="InstanceHandler{T}"/> class.
//    /// </summary>
//    [TestClass]
//    public class InstanceHandlerTests
//    {
//        /// <summary>
//        /// Runs test for instance handler can be constructed with data.
//        /// </summary>
//        [TestMethod]
//        public void InstanceHandlerCanBeConstructedWithDataTest()
//        {
//            String resolutionName = Guid.NewGuid().ToString();

//            InstanceHandler<Int32> target = new InstanceHandler<Int32>(resolutionName);

//            Assert.AreEqual(resolutionName, target.ResolutionName, "ResolutionName returned an incorrect value");
//        }

//        /// <summary>
//        /// Runs test for instance handler has value returns false for reference type with default value after instance has been called.
//        /// </summary>
//        [TestMethod]
//        public void InstanceHandlerHasValueReturnsFalseForReferenceTypeWithDefaultValueAfterInstanceHasBeenCalledTest()
//        {
//            String resolutionName = null;
//            IUnityContainer container = MockRepository.GenerateStub<IUnityContainer>();
//            String expected = null;

//            container.Stub(x => x.Resolve(typeof(String), resolutionName)).Return(expected);

//            try
//            {
//                InstanceManagerExtension.Container = container;

//                InstanceHandler<String> target = new InstanceHandler<String>(resolutionName);

//                String resolvedValue = target.Instance;

//                Assert.AreEqual(expected, resolvedValue, "Instance returned an incorrect value");

//                Boolean actual = target.HasValue;

//                Assert.IsFalse(actual, "HasValue returned an incorrect value");
//            }
//            finally
//            {
//                InstanceManagerExtension.Container = null;
//            }
//        }

//        /// <summary>
//        /// Runs test for instance handler has value returns false for reference type with default value before instance has been called.
//        /// </summary>
//        [TestMethod]
//        public void InstanceHandlerHasValueReturnsFalseForReferenceTypeWithDefaultValueBeforeInstanceHasBeenCalledTest()
//        {
//            String resolutionName = null;
//            IUnityContainer container = MockRepository.GenerateStub<IUnityContainer>();
//            String expected = null;

//            container.Stub(x => x.Resolve(typeof(String), resolutionName)).Return(expected);

//            try
//            {
//                InstanceManagerExtension.Container = container;

//                InstanceHandler<String> target = new InstanceHandler<String>(resolutionName);

//                Boolean actual = target.HasValue;

//                Assert.IsFalse(actual, "HasValue returned an incorrect value");
//            }
//            finally
//            {
//                InstanceManagerExtension.Container = null;
//            }
//        }

//        /// <summary>
//        /// Runs test for instance handler has value returns false for reference type with non default value before instance has been called.
//        /// </summary>
//        [TestMethod]
//        public void InstanceHandlerHasValueReturnsFalseForReferenceTypeWithNonDefaultValueBeforeInstanceHasBeenCalledTest()
//        {
//            String resolutionName = null;
//            IUnityContainer container = MockRepository.GenerateStub<IUnityContainer>();
//            String expected = Guid.NewGuid().ToString();

//            container.Stub(x => x.Resolve(typeof(String), resolutionName)).Return(expected);

//            try
//            {
//                InstanceManagerExtension.Container = container;

//                InstanceHandler<String> target = new InstanceHandler<String>(resolutionName);

//                Boolean actual = target.HasValue;

//                Assert.IsFalse(actual, "HasValue returned an incorrect value");
//            }
//            finally
//            {
//                InstanceManagerExtension.Container = null;
//            }
//        }

//        /// <summary>
//        /// Runs test for instance handler has value returns false for value type with default value after instance has been called.
//        /// </summary>
//        [TestMethod]
//        public void InstanceHandlerHasValueReturnsFalseForValueTypeWithDefaultValueAfterInstanceHasBeenCalledTest()
//        {
//            String resolutionName = null;
//            IUnityContainer container = MockRepository.GenerateStub<IUnityContainer>();
//            const Int32 Expected = 0;

//            container.Stub(x => x.Resolve(typeof(Int32), resolutionName)).Return(Expected);

//            try
//            {
//                InstanceManagerExtension.Container = container;

//                InstanceHandler<Int32> target = new InstanceHandler<Int32>(resolutionName);

//                Int32 resolvedValue = target.Instance;

//                Assert.AreEqual(Expected, resolvedValue, "Instance returned an incorrect value");

//                Boolean actual = target.HasValue;

//                Assert.IsFalse(actual, "HasValue returned an incorrect value");
//            }
//            finally
//            {
//                InstanceManagerExtension.Container = null;
//            }
//        }

//        /// <summary>
//        /// Runs test for instance handler has value returns false for value type with default value before instance has been called.
//        /// </summary>
//        [TestMethod]
//        public void InstanceHandlerHasValueReturnsFalseForValueTypeWithDefaultValueBeforeInstanceHasBeenCalledTest()
//        {
//            String resolutionName = null;
//            IUnityContainer container = MockRepository.GenerateStub<IUnityContainer>();
//            const Int32 Expected = 0;

//            container.Stub(x => x.Resolve(typeof(Int32), resolutionName)).Return(Expected);

//            try
//            {
//                InstanceManagerExtension.Container = container;

//                InstanceHandler<Int32> target = new InstanceHandler<Int32>(resolutionName);

//                Boolean actual = target.HasValue;

//                Assert.IsFalse(actual, "HasValue returned an incorrect value");
//            }
//            finally
//            {
//                InstanceManagerExtension.Container = null;
//            }
//        }

//        /// <summary>
//        /// Runs test for instance handler has value returns false for value type with non default value before instance has been called.
//        /// </summary>
//        [TestMethod]
//        public void InstanceHandlerHasValueReturnsFalseForValueTypeWithNonDefaultValueBeforeInstanceHasBeenCalledTest()
//        {
//            String resolutionName = null;
//            IUnityContainer container = MockRepository.GenerateStub<IUnityContainer>();
//            Int32 expected = Environment.TickCount;

//            container.Stub(x => x.Resolve(typeof(Int32), resolutionName)).Return(expected);

//            try
//            {
//                InstanceManagerExtension.Container = container;

//                InstanceHandler<Int32> target = new InstanceHandler<Int32>(resolutionName);

//                Boolean actual = target.HasValue;

//                Assert.IsFalse(actual, "HasValue returned an incorrect value");
//            }
//            finally
//            {
//                InstanceManagerExtension.Container = null;
//            }
//        }

//        /// <summary>
//        /// Runs test for instance handler has value returns true for reference type with non default value after instance has been called.
//        /// </summary>
//        [TestMethod]
//        public void InstanceHandlerHasValueReturnsTrueForReferenceTypeWithNonDefaultValueAfterInstanceHasBeenCalledTest()
//        {
//            String resolutionName = null;
//            IUnityContainer container = MockRepository.GenerateStub<IUnityContainer>();
//            String expected = Guid.NewGuid().ToString();

//            container.Stub(x => x.Resolve(typeof(String), resolutionName)).Return(expected);

//            try
//            {
//                InstanceManagerExtension.Container = container;

//                InstanceHandler<String> target = new InstanceHandler<String>(resolutionName);

//                String resolvedValue = target.Instance;

//                Assert.AreEqual(expected, resolvedValue, "Instance returned an incorrect value");

//                Boolean actual = target.HasValue;

//                Assert.IsTrue(actual, "HasValue returned an incorrect value");
//            }
//            finally
//            {
//                InstanceManagerExtension.Container = null;
//            }
//        }

//        /// <summary>
//        /// Runs test for instance handler has value returns true for value type with non default value after instance has been called.
//        /// </summary>
//        [TestMethod]
//        public void InstanceHandlerHasValueReturnsTrueForValueTypeWithNonDefaultValueAfterInstanceHasBeenCalledTest()
//        {
//            String resolutionName = null;
//            IUnityContainer container = MockRepository.GenerateStub<IUnityContainer>();
//            Int32 expected = Environment.TickCount;

//            container.Stub(x => x.Resolve(typeof(Int32), resolutionName)).Return(expected);

//            try
//            {
//                InstanceManagerExtension.Container = container;

//                InstanceHandler<Int32> target = new InstanceHandler<Int32>(resolutionName);

//                Int32 resolvedValue = target.Instance;

//                Assert.AreEqual(expected, resolvedValue, "Instance returned an incorrect value");

//                Boolean actual = target.HasValue;

//                Assert.IsTrue(actual, "HasValue returned an incorrect value");
//            }
//            finally
//            {
//                InstanceManagerExtension.Container = null;
//            }
//        }

//        /// <summary>
//        /// Runs test for instance handler returns instance resolved from extension.
//        /// </summary>
//        [TestMethod]
//        public void InstanceHandlerReturnsInstanceResolvedFromExtensionTest()
//        {
//            String resolutionName = Guid.NewGuid().ToString();
//            IUnityContainer container = MockRepository.GenerateStub<IUnityContainer>();
//            Int32 expected = Environment.TickCount;

//            container.Stub(x => x.Resolve(typeof(Int32), resolutionName)).Return(expected);

//            try
//            {
//                InstanceManagerExtension.Container = container;

//                InstanceHandler<Int32> target = new InstanceHandler<Int32>(resolutionName);

//                Int32 actual = target.Instance;

//                Assert.AreEqual(expected, actual, "Instance returned an incorrect value");
//                container.AssertWasCalled(x => x.Resolve(typeof(Int32), resolutionName));
//            }
//            finally
//            {
//                InstanceManagerExtension.Container = null;
//            }
//        }

//        /// <summary>
//        /// Runs test for instance handler returns instance resolved from extension without resolution name.
//        /// </summary>
//        [TestMethod]
//        public void InstanceHandlerReturnsInstanceResolvedFromExtensionWithoutResolutionNameTest()
//        {
//            String resolutionName = null;
//            IUnityContainer container = MockRepository.GenerateStub<IUnityContainer>();
//            Int32 expected = Environment.TickCount;

//            container.Stub(x => x.Resolve(typeof(Int32), resolutionName)).Return(expected);

//            try
//            {
//                InstanceManagerExtension.Container = container;

//                InstanceHandler<Int32> target = new InstanceHandler<Int32>(resolutionName);

//                Int32 actual = target.Instance;

//                Assert.AreEqual(expected, actual, "Instance returned an incorrect value");
//                container.AssertWasCalled(x => x.Resolve(typeof(Int32), resolutionName));
//            }
//            finally
//            {
//                InstanceManagerExtension.Container = null;
//            }
//        }

//        /// <summary>
//        /// Runs test for instance handler returns previously resolved instance on subsequent calls.
//        /// </summary>
//        [TestMethod]
//        public void InstanceHandlerReturnsPreviouslyResolvedInstanceOnSubsequentCallsTest()
//        {
//            String resolutionName = Guid.NewGuid().ToString();
//            IUnityContainer container = MockRepository.GenerateStub<IUnityContainer>();
//            Int32 expected = Environment.TickCount;

//            container.Stub(x => x.Resolve(typeof(Int32), resolutionName)).Return(expected).Repeat.Once();

//            try
//            {
//                InstanceManagerExtension.Container = container;

//                InstanceHandler<Int32> target = new InstanceHandler<Int32>(resolutionName);

//                Int32 first = target.Instance;
//                Int32 second = target.Instance;
//                Int32 third = target.Instance;

//                Assert.AreEqual(expected, first, "Instance returned an incorrect value");
//                Assert.AreEqual(first, second, "Instance returned an incorrect value");
//                Assert.AreEqual(second, third, "Instance returned an incorrect value");
//                container.AssertWasCalled(x => x.Resolve(typeof(Int32), resolutionName));
//            }
//            finally
//            {
//                InstanceManagerExtension.Container = null;
//            }
//        }

//        /// <summary>
//        /// Gets or sets the test context which provides
//        ///   information about and functionality for the current test run.
//        /// </summary>
//        /// <value>
//        /// The test context.
//        /// </value>
//        public TestContext TestContext
//        {
//            get;
//            set;
//        }
//    }
//}